import { onMounted,onUnmounted ,ref} from "vue"
import { throttle } from 'underscore'


function useScroll(){
    let isScroll=ref(false)

    const clientHeight = ref(0)
    const scrollTop = ref(0)
    const scrollHeight = ref(0)
      // 监听窗口的滚动
  const addScroll=throttle(()=>{
    clientHeight.value=document.documentElement.clientHeight
    scrollHeight.value=document.documentElement.scrollHeight
    scrollTop.value=document.documentElement.scrollTop
   if((clientHeight+scrollTop) >= scrollHeight){
     //再次请求数据
      isScroll.value=true   
    //  console.log('触发了滚动');
     
   }  
 },100)
    onMounted(()=>{
        window.addEventListener('scroll',addScroll)
    })
    onUnmounted(()=>{
        window.removeEventListener('scroll',addScroll)
    })

    return {isScroll,useScroll,clientHeight,scrollTop,scrollHeight}
}




  export default useScroll